<template>
    <div>
        <el-col :span="24" class="action-bar">
            <el-button type="primary" size="medium" >
                <router-link to="SystemMsgEditor" tag="div">添加</router-link>
            </el-button>
        </el-col>

        <el-table
            :data="tableData"
            style="width: 100%">
            <el-table-column
                prop="title"
                label="标题"
                min-width="100"
                
                >
            </el-table-column>
            <el-table-column
                prop="desc"
                label="描述"
                min-width="100"
                
                >
            </el-table-column>
            <el-table-column
                prop="date"
                label="封面图片"
                width="200"
                
                >
                <template slot-scope="scope">
                    <div>
                        <img :src="scope.row.thumb_url" alt="" style="width:120px;height:80px;objectFit:contain">
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="created_at"
                label="更新时间"
                width="180">
            </el-table-column>
            <el-table-column label="操作" min-width='200'>
                <template slot-scope="scope">
                    <el-button  type="primary" @click="editReason(scope.row.id)">编辑</el-button>
                    <el-button  type="primary" @click="delSysNews(scope.row.id)">删除</el-button>
                </template>
            </el-table-column>
            
        </el-table>
        <el-col :span="24" class="footer-bar">
			<div class="page-code">
				<el-pagination
					background
					:page-size="16"
					layout="prev, pager, next"
					:total="totalPage"
					@current-change="pageChange"
						>
				</el-pagination>
			</div>
    </el-col>
    </div>
</template>
<script>
export default {
    name:'member',
    data() {
        return {
            tableData: [{}],
            page:1,
            totalPage:0
        }
    },
    methods: {
        search(){
            this.page=1;
            this.getSysNewsList()
        },
        async getSysNewsList(){
            //获取会员列表
            let params={
                page:this.page,
                limit:16,
            }
            let res=await this.$api.getSysNewsList(
                params);
            if(res.data.level=='success'){
                this.tableData=res.data.data;
                this.totalPage=res.data.page_info.total;
            }
        },
        pageChange(e){
			//翻页
			this.page=e;
			this.getSysNewsList();
        },
        initData(){
            this.reason='';
            this.sortNum=''
        },
        editReason(id){
            //编辑
            this.$router.push({name:'SystemMsgEditor',query:{id:id}})
        },
        async delSysNews(id){
            //删除
            let judge=null
            try {
              judge=  await this.$confirm('删除该系统消息?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
                })
            } catch (error) {
                judge='cancel'
            }
            if (judge){
                let res=await this.$api.delSysNews({id:id});
                if(res.data.level=='success'){
                this.$message({
                        type:'success',
                        message:res.data.message
                    })
                    this.getSysNewsList()
                }else{
                    this.$message({
                        type:'error',
                        message:res.data.message
                    })
                    
                }
            }
            console.log(judge)
        },
        submit(){

        }

    },
    mounted() {
        this.getSysNewsList()
    },
}
</script>
<style lang="scss" scoped>
    .action-bar{
			background-color: #f2f2f2;
			height: 60px;
			margin: 10px 0px;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			padding-left: 20px;
			.action-bar-input{
				width: 250px;
				margin-right: 14px;
      }
      .task-form-text{
				color: #666666;
			}
		}
		.el-table-style{
			width: 100%;
			border: 1px solid #f2f2f2;
		}
		.footer-bar{
			display: flex;
			justify-content: space-between;
			align-items: center;
			background: #f2f2f2;
			padding: 8px;
			margin: 10px 0px;
			box-sizing: border-box;
		}
		.dialog-footer{
			text-align: center;
		}
		.executorList{
			display: flex;
			flex-wrap: wrap;
			div{
				margin:10px;
				border:1px solid #eee;
				border-radius: 5px;
				padding:5px 10px;
			}
		}
</style>